<?php


namespace app\api\controller;

use \app\api\model\Schedule as ScheduleModel;
use app\api\model\SignIn;
use think\Controller;
use think\Request;

class Schedule extends Controller
{
    protected $middleware = ['Auth'];
    /**
     * 学生的课程列表
     */
    public function scheduleStudentList(Request $request){
        $userid = $request->userId;
        $result = ScheduleModel::scheduleStudentList($userid);
        if($result){
            return  success($result);
        }else{
            return  fail(DATA_NOT_EXIST, '查询失败');
        }
    }

    /**
     * 学生签到
     */
    public function studentSignIn(Request $request){
        $userid = $request->userId;
        $scheduleId  = input('?post.id') ? input('post.id') : 0;
        if(!$scheduleId){
            return  fail(DATA_NOT_EXIST, '参数错误');
        }
        $result = SignIn::signin($userid,$scheduleId);
        if($result){
            return  success($result);
        }else{
            return  fail(DATA_NOT_EXIST, '签到失败');
        }
    }


    /**
     * 教师的课程列表
     */
    public function  scheduleTeachertList(Request $request){
        $userid = $request->userId;
        $result = ScheduleModel::scheduleTeacherList($userid);
        if($result){
            return  success($result);
        }else{
            return  fail(DATA_NOT_EXIST, '查询失败');
        }
    }

    /**
     * 根据课程id查询该课程下所有学生信息列表
     */
    public function  StudentList(){
        $id  = input('?get.id') ? input('get.id') : 0;
        if(!$id){
            return  fail(DATA_NOT_EXIST, '参数错误');
        }
        $result = ScheduleModel::StudentList($id);
        if($result){
            return  success($result);
        }else{
            return  fail(DATA_NOT_EXIST, '查询失败');
        }
    }
}